import { action, computed, observable } from "mobx";
import Toast from "../../utils/Toast";
import AccountRequestManager from "../../api/AccountRequestManager";

export default class LoginViewModel {
    @observable userName = '';
    @observable userPwd = '';

    login() {
        //Toast.show(this.userName)
        if (!this.checkSubInfo()) {
            return
        }

        console.log(global.token)
        AccountRequestManager.login(this.userName, this.userPwd).then((res) => {
            console.log("===========######## call succ===============")
            console.log(res.loginName)
        }, (er) => {
            console.log("===========######## call fail===============")
            console.log(er)
        })
    }

    checkSubInfo() {
        if (this.userName == '') {
            Toast.show("请输入用户名")
            return false
        }

        if (this.userPwd == '') {
            Toast.show("请输入密码")
            return false
        }

        return true
    }

    @computed
    getName() {
        return this.userName
    }

    @computed
    getPwd() {
        return this.userPwd
    }

    @action
    setNameText(name: String) {
        this.userName = name
    }

    @action
    setPwdText(pwd: String) {
        this.userPwd = pwd
    }

}